{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "PRESET = os.environ.setdefault(\"PRESET\", \"millionaires\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import asyncio\n",
    "from opentelemetry import trace\n",
    "from opentelemetry.sdk.environment_variables import OTEL_SERVICE_NAME\n",
    "\n",
    "from secretnote.instrumentation.sdk import (\n",
    "    dump_tracing_context,\n",
    "    setup_debug_exporter,\n",
    "    setup_tracing,\n",
    ")\n",
    "\n",
    "os.environ[OTEL_SERVICE_NAME] = f\"{PRESET}:driver\"\n",
    "setup_tracing()\n",
    "setup_debug_exporter()\n",
    "\n",
    "tracer = trace.get_tracer(__name__)\n",
    "\n",
    "with tracer.start_as_current_span(\"caller\"):\n",
    "    tracing_context = dump_tracing_context()\n",
    "\n",
    "    p1, p2 = await asyncio.gather(\n",
    "        asyncio.create_subprocess_exec(\n",
    "            \"jupyter\",\n",
    "            \"execute\",\n",
    "            \"sim.ipynb\",\n",
    "            env={\n",
    "                **os.environ,\n",
    "                **tracing_context,\n",
    "                \"SELF_PARTY\": \"alice\",\n",
    "                \"RAY_ADDRESS\": \"127.0.0.1:32400\",\n",
    "            },\n",
    "        ),\n",
    "        asyncio.create_subprocess_exec(\n",
    "            \"jupyter\",\n",
    "            \"execute\",\n",
    "            \"sim.ipynb\",\n",
    "            env={\n",
    "                **os.environ,\n",
    "                **tracing_context,\n",
    "                \"SELF_PARTY\": \"bob\",\n",
    "                \"RAY_ADDRESS\": \"127.0.0.1:32401\",\n",
    "            },\n",
    "        ),\n",
    "    )\n",
    "\n",
    "    await asyncio.gather(p1.wait(), p2.wait())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
